package dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.hibernate.service.spi.Manageable;
import org.springframework.stereotype.Repository;

import dao.CategoriesDao;
import pojo.Categories;
import pojo.Food;

@Repository
public class CategoriesDaoImpl implements CategoriesDao {

	@PersistenceContext(name="un")
	private EntityManager manager; 
	
	@Override
	public Categories add(Categories t) {
		manager.persist(t);
		return t;
	}

	@Override
	public List<Categories> findAll() {
		String hq = "select c from Categories c";
		List<Categories> categoriesList = (List<Categories>) manager.createQuery(hq)
				.getResultList();
		return categoriesList;
	}

	@Override
	public Categories load(String categoryId) {
		
		return manager.find(Categories.class, categoryId);
	}
	
}
